//三个点越接近一条直线，这个圆最大
typedef struct _GL2_fPoint {
    float x;
    float y;
} GL2_fPoint;

// 计算通过三点的圆的圆心和半径
bool circle_from_three_points(const GL2_fPoint& p1, const GL2_fPoint& p2, const GL2_fPoint& p3, float& cx, float& cy, float& r) {
    float x1 = p1.x, y1 = p1.y;
    float x2 = p2.x, y2 = p2.y;
    float x3 = p3.x, y3 = p3.y;

    float A = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
    if (std::abs(A) < 1e-6f) {
        return false;
    }

    float B = (x1 * x1 + y1 * y1) * (y3 - y2) + (x2 * x2 + y2 * y2) * (y1 - y3) + (x3 * x3 + y3 * y3) * (y2 - y1);
    float C = (x1 * x1 + y1 * y1) * (x2 - x3) + (x2 * x2 + y2 * y2) * (x3 - x1) + (x3 * x3 + y3 * y3) * (x1 - x2);
    float D = (x1 * x1 + y1 * y1) * (x3 * y2 - x2 * y3) + (x2 * x2 + y2 * y2) * (x1 * y3 - x3 * y1) + (x3 * x3 + y3 * y3) * (x2 * y1 - x1 * y2);

    cx = -B / (2 * A);
    cy = -C / (2 * A);
    r = std::sqrt((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy));
    
    return true;
}
